
// Function SMM Loss Function (GMM) // AG
double SMM(double *momentsobv, double *momentsgen, double covmatrixe[nbmoments][nbmoments]) {
	double *arg1, *matrix1, minLossfun;
	arg1 = (double *) calloc((nbmoments), sizeof(double));
	matrix1 = (double *) calloc((nbmoments), sizeof(double));
	
	for(int i=0; i < nbmoments; i++) {
		arg1[i] = (momentsobv[i] - momentsgen[i])*(momentsobv[i] - momentsgen[i]);
	} // get a 1xN matrix
	
	for(int i=0; i < nbmoments; i++) {
		matrix1[i] = 0.0;
		for(int j = 0; j < nbmoments; j++) {
			matrix1[i] += arg1[j]*covmatrixe[j][i]; // covmatrix is of size NxN
		}
	} // get a 1xN matrix
	
	minLossfun = 0.0;
	for(int i=0; i < nbmoments; i++) {
		minLossfun += matrix1[i]*arg1[i];
	} // get a 1x1 object
	
	return minLossfun;
}

